package com.hxz.graduationdesign;

import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.Objects;

public class Standby {

    public static boolean isWithin365Days(Date targetDate) {
        Objects.requireNonNull(targetDate, "日期不能为 null");

        // 转换为 LocalDate（使用系统默认时区）
        LocalDate date = targetDate.toInstant()
                .atZone(ZoneId.systemDefault())
                .toLocalDate();

        // 获取当前日期（相同时区）
        LocalDate today = LocalDate.now(ZoneId.systemDefault());

        // 计算天数差（date早于today时差值为正）
        long daysBetween = ChronoUnit.DAYS.between(date, today);

        return daysBetween <= 365 && daysBetween >= 0;
    }

    // 测试
    public static void main(String[] args) {

        System.out.println("当天: " + isWithin365Days(new Date()));

    }
}